/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : levelLogic
	/// </summary>
	public class LevelRegionPOD : IPOD 
    {
        public readonly static Func<LevelRegionPOD> FACTORY = () => new LevelRegionPOD();
		public static Func<LevelRegionPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public int cid;
		/// <summary>
        /// 
        /// </summary>
        private List<LevelEntityPOD> m_entities;
		/// <summary>
        /// 
        /// </summary>
        private List<int> m_effectCids;
		/// <summary>
        /// audio.Id, 策划自定义bgm，优先级最高，0表示没有，-1表示静音
        /// </summary>
		public int customBgmCid;
		/// <summary>
        /// 天气类型，key是天气id，为0时表示全局天气
        /// </summary>
        private Dictionary<int, int> m_customWeathers;
		
		
        public List<LevelEntityPOD> entities
        {
            get
            {
                if(m_entities == null)
                {
                    m_entities = new();
                }
                return m_entities;
            }
            private set => m_entities = value;
        }
        public List<LevelEntityPOD> unsafe_entities
        {
        	get => m_entities;
        	set => m_entities = value;
        }
        public List<int> effectCids
        {
            get
            {
                if(m_effectCids == null)
                {
                    m_effectCids = new();
                }
                return m_effectCids;
            }
            private set => m_effectCids = value;
        }
        public List<int> unsafe_effectCids
        {
        	get => m_effectCids;
        	set => m_effectCids = value;
        }
        public Dictionary<int, int> customWeathers
        {
            get
            {
                if(m_customWeathers == null)
                {
                    m_customWeathers = new();
                }
                return m_customWeathers;
            }
            private set => m_customWeathers = value;
        }
        public Dictionary<int, int> unsafe_customWeathers
        {
        	get => m_customWeathers;
        	set => m_customWeathers = value;
        }
		
		/*-- constructors --*/
		public LevelRegionPOD() {}
		public LevelRegionPOD(int cid, List<LevelEntityPOD> entities, List<int> effectCids, int customBgmCid, Dictionary<int, int> customWeathers) {
			this.cid = cid;
			this.m_entities = entities;
			this.m_effectCids = effectCids;
			this.customBgmCid = customBgmCid;
			this.m_customWeathers = customWeathers;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_int(cid);
            _out.Write_list_pod(m_entities);
            _out.Write_list_int(m_effectCids); 
            _out.Write_int(customBgmCid);
            _out.Write_map_int_int(m_customWeathers);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_entities = _in.Read_list_pod<LevelEntityPOD>(LevelEntityPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_effectCids = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            customBgmCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_customWeathers = _in.Read_map_int_int();
        }
		
		public LevelRegionPOD Clone() {
            LevelRegionPOD o = DynamicFactory();
            o.cid = cid;
            if (m_entities != null) {
                o.m_entities = m_entities.ConvertAll(o => o?.Clone());
            }
            if (m_effectCids != null) {
                o.m_effectCids = new (m_effectCids);
            }
            o.customBgmCid = customBgmCid;
            if (m_customWeathers != null) {
                o.m_customWeathers = new (m_customWeathers);
            }
            return o;
        }
        
        public void Clear() {
            cid = default;
            m_entities = default;
            m_effectCids = default;
            customBgmCid = default;
            m_customWeathers = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "LevelRegionPOD [";
			str += "cid=";
			str += cid;
			str += ", entities=";
			str += m_entities.ToString<LevelEntityPOD>();
			str += ", effectCids=";
			str += m_effectCids.ToString<int>();
			str += ", customBgmCid=";
			str += customBgmCid;
			str += ", customWeathers=";
			str += m_customWeathers.ToString<int, int>();
			str += "]";
			return str;
		}
		
	}
}